package com.wiscamp.ninechapters.problems.domain.services;

import com.wiscamp.ninechapters.problems.domain.models.collections.CollectionPart;
import com.wiscamp.ninechapters.problems.domain.models.collections.CollectionSection;
import com.wiscamp.ninechapters.problems.domain.repositories.CollectionPartRepository;
import cube.ddd.aspect.HandleServiceException;
import cube.ddd.domain.BaseDomainService;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import org.springframework.stereotype.Service;

@Service
public class CollectionPartService extends BaseDomainService {

    private final CollectionPartRepository collectionPartRepository;

    public CollectionPartService(CollectionPartRepository collectionPartRepository) {
        this.collectionPartRepository = collectionPartRepository;
    }

    // region part & section

    /*@HandleServiceException
    public Collection<CollectionPart> getCollectionParts(@NotNull long collectionId) {
        return collectionPartRepository.getPartsByCollection(collectionId);
    }

    @HandleServiceException
    public CollectionPart getCollectionPart(@NotNull long partId) {
        return collectionPartRepository.getPart(partId);
    }*/

    /**
     * Creates a paper part
     *
     * @param part
     * @return
     */
    @HandleServiceException
    public CollectionPart createCollectionPart(@NotNull CollectionPart part, long operatorId) {
        return collectionPartRepository.saveCollectionPart(part);
    }

    /**
     * Updates a paper part
     *
     * @param part
     * @return
     */
    @HandleServiceException
    public CollectionPart updateCollectionPart(@NotNull CollectionPart part, long operatorId) {
        return collectionPartRepository.saveCollectionPart(part);
    }

    /**
     * Deletes a paper part
     *
     * @param partId
     * @return
     */
    @HandleServiceException
    public boolean deleteCollectionPart(@Min(0) long partId, long operatorId) {
        collectionPartRepository.deleteCollectionPart(partId);
        return true;
    }

    /*@HandleServiceException
    public Collection<CollectionSection> getCollectionSections(@Min(0) long partId) {
        return collectionPartRepository.getPaperSections(partId);
    }

    @HandleServiceException
    public CollectionSection getCollectionSection(@Min(0) long sectionId) {
        return collectionPartRepository.getSection(sectionId);
    }*/

    /**
     * Creates a paper section
     *
     * @param section
     * @return
     */
    @HandleServiceException
    public CollectionSection createCollectionSection(@NotNull CollectionSection section, long operatorId) {
        return collectionPartRepository.saveCollectionSection(section);
    }

    /**
     * Updates a paper section
     *
     * @param section
     * @return
     */
    @HandleServiceException
    public CollectionSection updateCollectionSection(@NotNull CollectionSection section, long operatorId) {
        return collectionPartRepository.saveCollectionSection(section);
    }

    /**
     * Deletes a paper section
     *
     * @param sectionId
     * @return
     */
    @HandleServiceException
    public boolean deleteCollectionSection(@Min(0) long sectionId, long operatorId) {
        collectionPartRepository.deleteCollectionSection(sectionId);
        return true;
    }
    // endregion
}
